<template>
	<view>
		<nav-bars title="手机号绑定"></nav-bars>
		<view class="BindPhone">
			<view class="BindPhone_nav">绑定手机号</view>
			<view class="BindPhone_num">绑定本机号码: {{ Phone }}</view>
			<view class="BindPhone_code">
				<input type="text" v-model="verification" placeholder="请输入短信验证码" placeholder-style="color:#999999;" />
				<view class="BindPhone_send" v-if="disabled == false" @tap="GetVerificationCode">{{ sendTime }}</view>
				<view class="BindPhone_disabled" v-else>{{ sendTime }}</view>
			</view>
			<view class="BindPhone_btn">
				<view class="BindPhone_sure" @click="SureBinPhone">确认绑定</view>
				<view class="BindPhone_Change" @click="GoChangePhoen">更换手机号绑定</view>
			</view>
		</view>
	</view>
</template>
<script>
import Https from '@/service/verification.js';
var Rexphone = /^1[2|3|4|5|6|7|8|9]\d{9}$/;
export default {
	data() {
		return {
			sendTime: '发送验证码', //倒计时
			currentTime: 60,
			disabled: false,
			Phone: uni.getStorageSync('userMobile'),
			verification: '' //验证码
		};
	},
	methods: {
		SureBinPhone() {
			var that = this;
			let params = {
				phone: that.Phone,
				sms_code: that.verification
			};
			if (that.verification != '') {
				Https.SetbindPhone(params).then(res => {
					if (res.code == 1) {
						console.log(res);
						uni.showToast({
						  title: '绑定成功',
						  icon: 'success',
						  duration: 2000
						})
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},2200)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				});
			}
			if (that.verification == '') {
				uni.showToast({
					title: '请上输入手机验证码',
					icon: 'none',
					duration: 2000
				});
				return;
			}
		},
		GoChangePhoen() {
			uni.navigateTo({
				url: '/pages_Verification/verification/bindPhone/ChangePhone'
			});
		},
		GetVerificationCode() {
			var that = this;
			let params = {
				phone: that.Phone
			};
			Https.sendVerificationCode(params).then(res => {
				if (res.code == 1) {
					uni.showToast({
						title: '发送成功',
						icon: 'success',
						duration:2000
					});
					that.GetCode();
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
				}
			});
		},
		// 获取验证码的时间倒计时
		GetCode: function(options) {
			var that = this;
			var currentTime = that.currentTime;
			var interval = setInterval(function() {
				currentTime--;
				that.disabled = true;
				that.sendTime = currentTime + '秒后重发';
				if (currentTime <= 0) {
					clearInterval(interval);
					that.sendTime = '重新发送';
					that.currentTime = 60;
					that.disabled = false;
				}
			}, 1000);
		}
	}
};
</script>
<style lang="less">
page {
	background: #fff;
}
.BindPhone {
	padding: 32rpx;
	.BindPhone_nav {
		font-size: 60rpx;
		font-weight: 500;
		color: #333333;
		margin-top: 140rpx;
		margin-bottom: 26rpx;
	}
	.BindPhone_num {
		font-size: 34rpx;
		font-weight: 500;
		color: #c3ab7c;
	}
	.BindPhone_code {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 200rpx;
		padding-bottom: 30rpx;
		border-bottom: 2rpx solid #f1f1f1;
		input {
			flex: 1;
			margin-right: 30rpx;
			height: 100%;
			font-size: 30rpx;
		}
		.BindPhone_send {
			margin-right: 40rpx;
			font-size: 30rpx;
			font-weight: bold;
			color: #c3ab7c;
		}
		.BindPhone_disabled {
			margin-right: 40rpx;
			font-size: 30rpx;
			font-weight: bold;
			color: #999999;
		}
	}
	.BindPhone_btn {
		padding-top: 50rpx;
		.BindPhone_sure {
			font-size: 34rpx;
			font-weight: 500;
			color: #ffffff;
			height: 90rpx;
			background: #c3ab7c;
			border-radius: 10rpx;
			margin-bottom: 30rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
		.BindPhone_Change {
			height: 90rpx;
			border: 2rpx solid #c3ab7c;
			border-radius: 10rpx;
			font-size: 34rpx;
			font-weight: 500;
			color: #c3ab7c;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
}
</style>
